

#include "data_global.h"
#include "led.h"

extern pthread_mutex_t mutex_led;
extern pthread_cond_t  cond_led;
extern unsigned char  cmd_led;



//led灯控制线程 
void *pthread_led(void *arg)
{
	int fd;
	int led = 2;
	fd = open(LED_DEV,O_RDWR);
	if(fd < 0){
		printf("open led device file failed ... \n");
		return NULL;
	}
	printf("pthread_led\n");
	while(1){
		pthread_mutex_lock(&mutex_led);
		pthread_cond_wait(&cond_led, &mutex_led);
		if(cmd_led == 0x41){
			//打开所有的LED 2 3 4 5
			while(led <= 5){
				printf("led: %d\n", led);
				ioctl(fd, LED_ON, &led);
				led++;
			}
			led = 2;
		}else{
			//关闭所有的LED 2 3 4 5
			while(led <= 5){
				ioctl(fd, LED_OFF, &led);
				led++;
			}
			led = 2;
		}
		pthread_mutex_unlock(&mutex_led);
	}

	close(fd);
}
